﻿<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    exclude-result-prefixes="msxsl"
    xmlns:dt="urn:schemas-microsoft-com:datatypes"
    xmlns:mr2="http://www.wales.nhs.uk/namespaces/MessageRelease2">
  
  <xsl:output version="4.0" method="html" indent="no"  omit-xml-declaration="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>

   <xsl:template match="//documents">
     <table id="documents" class="selectable">
       <thead>
       <tr>
         <th>Document Type</th>
         <th>Author</th>
         <th>Creation Date</th>
         <th>Revoked</th>
         <th>Sensitive</th>
       </tr>
       </thead>
       <tbody>
      <xsl:for-each select="DocumentStructure">
        <xsl:variable name="documentid" select="mr2:DocumentVersion/mr2:Header/mr2:DocumentId" />
        <xsl:variable name="sensitive">
          <xsl:choose>
            <xsl:when test="mr2:DocumentVersion/mr2:Header/mr2:SensitivityTypeCode = '0'">false</xsl:when>
            <xsl:otherwise>true</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>




        <xsl:variable name="rowclass">
          <xsl:choose>
            <xsl:when test="position() mod 2 = 0">document alt</xsl:when>
            <xsl:otherwise>document</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
          <tr documentid='{$documentid}' class='{$rowclass}' sensitive='{$sensitive}'>
          <td><xsl:value-of select="mr2:DocumentVersion/mr2:Header/mr2:DocumentAttribute[mr2:Attribute='DocumentTypeCode']/mr2:Value"/></td>
          <td><xsl:value-of select="mr2:DocumentVersion/mr2:Header/mr2:DocumentAttribute[mr2:Attribute='Author']/mr2:Value"/></td>
          <td><xsl:value-of select="msxsl:format-date(mr2:DocumentVersion/mr2:Header/mr2:DocumentDateTime, 'MMM dd, yyyy')"/> (<xsl:value-of select="msxsl:format-time(mr2:DocumentVersion/mr2:Header/mr2:DocumentDateTime, 'hh:mm')"/>)</td>
          <td><xsl:value-of select="mr2:DocumentVersion/mr2:Header/mr2:Revoked"/></td>
          <td><xsl:value-of select="$sensitive"/></td>
        </tr>
      </xsl:for-each>
       </tbody>
    </table>
  </xsl:template>

</xsl:stylesheet>
